package com.brotherly.framework.net;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

public class NetResponse
{
    public static final int ERROR = 0;
    public static final int OK = 200;

    public int code;
    public byte[] resultBytes;
    public String result;
    public String extraInfo = "";
    public Map<String, String> headers = new HashMap<String, String>();

    public JSONObject toJSONObject()
    {
        JSONObject jobject = new JSONObject();
        try
        {
            jobject.put("code", code);
            jobject.put("result", result);
            jobject.put("extraInfo", extraInfo);

            JSONObject headsObj = new JSONObject();

            if (headers != null)
            {
                for (Map.Entry<String, String> entry : headers.entrySet())
                {
                    String name = entry.getKey();
                    String value = entry.getValue();

                    headsObj.put(name, value);
                }
            }

            jobject.put("headers", headsObj);

        }
        catch (JSONException e)
        {
            e.printStackTrace();
        }
        return jobject;
    }
}
